/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Chat;

import Core.ReaderThread;
import Slave.SlaveClient;
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Graphics;

/**
 *
 * @author mrbao
 */
public class SplashForm extends Canvas implements Runnable {

    private String message = "Dang ket noi...";
    private String username;
    private String password;
    private boolean invisible;

    public SplashForm(String username, String password, boolean invisible) {
        this.username = username;
        this.password = password;
        this.invisible = invisible;
        new Thread(this).start();
    }

    protected void paint(Graphics g) {
        this.setFullScreenMode(true);
        Util.ClearScreen(g, getWidth(), getHeight());
        g.setColor(0);
        g.setFont(Util.fontMedium);
        g.drawString(message, (getWidth() - Util.fontMedium.stringWidth(message)) / 2, (getHeight() - Util.fontMedium.getHeight()) / 2, 0);
    }
    private ReaderThread readerThread;

    public void run() {
        if (Yahoo.slaveClient == null) {
            Yahoo.slaveClient = new SlaveClient("localhost", 9999);
        }
        Yahoo.slaveClient.Login(username, password, invisible);
        readerThread = Yahoo.slaveClient.GetReaderThread();

        while (true) {
            if (!readerThread.GetQueue().isEmpty()) {
                for (int i = 0; i < readerThread.GetQueue().size(); i++) {
                    String message = readerThread.GetQueue().elementAt(i).toString();
                    if (message.equals("LINRS:NOT_NULL")) {
                        Yahoo.DisplayChat();
                    } else {
                        Yahoo.DisplayLogin();
                    }
                }
            }
        }
    }
}
